<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_role', function (Blueprint $table) {
            $table->id();
            $table->string('name', 20)->default('')->comment('角色名称');
            $table->json('menu_ids')->comment('菜单集');
            $table->json('menu_half_ids')->comment('半选菜单集');
            $table->string('description', 255)->default('')->comment('角色介绍');
            $table->integer('group_id')->default(0)->comment('组织id');
            $table->tinyInteger('is_show')->default(1)->comment('是否展示:0=否,1=是');
            $table->tinyInteger('status')->default(0)->comment('状态:1=正常,2=禁用');
            $table->tinyInteger('is_delete')->default(0)->comment('是否删除:1=删除,0=正常');
            $table->integer('created_at')->default(0)->comment('创建时间');
            $table->integer('updated_at')->default(0)->comment('修改时间');
        });
        DB::statement("ALTER TABLE `admin_role` comment '【后台】角色'");
        // 初始化管理员表
        DB::table('admin_role')->insert([
            'name'        => '超级管理员',
            'menu_ids'    => json_encode([]),
            'menu_half_ids' => json_encode([]),
            'description' => '超级管理员',
            'is_show'     => 0,
            'status'      => 1,
            'created_at'  => time(),
            'updated_at'  => time()
        ]);
        // 初始化管理员表
        DB::table('admin_role')->insert([
            'name'        => '管理员',
            'menu_ids'    => json_encode([4,15,14,13,12,5,19,18,17,16,6,21,22,23,20,24,25]),
            'menu_half_ids' => json_encode([1,2]),
            'description' => '超级管理员',
            'is_show'     => 1,
            'status'      => 1,
            'created_at'  => time(),
            'updated_at'  => time()
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_role');
    }
};
